<template>
  <div class="main">
    <div class="Loginarea" @click="showPopup">
      <img src="@/assets/avatar.png">
      <span v-if="errno!== 0">用户登录注册&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;></span>
      <span v-else>{{loginlist}}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;></span>
    </div>
    <div class="wenzimain">
      <div class="wenzi">
        <div>
          <van-icon name="photo-o" size=".24rem" />
          <span>文字</span>
        </div>
      </div>
      <div class="wenzi">
        <div>
          <van-icon name="photo-o" size=".24rem" />
          <span>文字</span>
        </div>
      </div>
      <div class="wenzi">
        <div>
          <van-icon name="photo-o" size=".24rem" />
          <span>文字</span>
        </div>
      </div>
      <div class="wenzi">
        <div>
          <van-icon name="photo-o" size=".24rem" />
          <span>文字</span>
        </div>
      </div>
    </div>
    <van-popup v-model="show" class="vanpopup">
      <LoginFrom @giveFather="getSon" />
    </van-popup>
  </div>
</template>

<script>
import LoginFrom from '@/components/loginfrom.vue'
import { mapState } from 'vuex'
export default {
  name: 'user',
  data() {
    return {
      //弹出层显示的判断条件
      show: false,
      //用户名
      loginlist: '',
      errno: ''
    }
  },
  computed: {},
  updated() {
    //登录成功后，把在本地存储的用户名，赋值到组件上
    let data2 = JSON.parse(localStorage.getItem('nickname'))
    let errno = JSON.parse(localStorage.getItem('errno'))
    setTimeout(() => {
      this.loginlist = data2
      this.errno = errno
    }, 500)
  },
  mounted() {
    //登录成功后，把在本地存储的用户名，赋值到组件上
    let data2 = JSON.parse(localStorage.getItem('nickname'))
    let errno = JSON.parse(localStorage.getItem('errno'))
    setTimeout(() => {
      this.loginlist = data2
      this.errno = errno
    })
  },
  components: {
    LoginFrom
  },
  methods: {
    //点击登录弹出层显示
    showPopup() {
      this.show = true
      //如果已是登录的状态，点击登录面板是无效的
      let token = localStorage.getItem('token')
      if (token) {
        if (this.loginlist.length > 1) {
          this.show = false
        }
      }
    },
    //接收子组件的值
    getSon(temp) {
      //接收子组件传过来的值，把把赋值给show，这样就把弹出层给关了
      this.show = temp
    }
  }
}
</script>

<style lang="less" scoped>
.main {
  .Loginarea {
    background-color: #333;
    display: flex;
    justify-content: space-between;
    align-items: center;
    img {
      padding: 5% 5%;
      width: 20%;
      height: 20%;
      border-radius: 50%;
    }
    span {
      padding: 5% 5%;
      color: #fff;
      font-size: 0.18rem;
    }
  }
  .wenzimain {
    display: flex;
    flex-wrap: wrap;
    .wenzi {
      background-color: #fff;
      display: flex;
      flex-direction: column;
      align-items: center;
      width: 33%;
      border-bottom: 1px solid #e5e5e5;
      border-right: 1px solid #e5e5e5;
      div {
        padding: 40% 0%;
      }
      van-icon {
      }
    }
  }
  .vanpopup {
    width: 80%;
  }
}
</style>